package com.chencs.app.config.controller;

import com.alibaba.fastjson.JSON;
import com.chencs.app.config.service.AppConfigService;
import com.chencs.vo.net.request.AdviseRequest;
import com.chencs.vo.net.request.CategoryRequest;
import com.chencs.vo.net.request.ProductRequest;
import com.chencs.vo.net.request.RequestBase;
import com.chencs.vo.net.response.TagResponse;
import framework.model.ResponseOptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/10/10.
 */


@RestController
@RequestMapping("/app/config")
public class AppConfigController {


    @Autowired
    private AppConfigService appConfigService;
    @RequestMapping(value = "/checkVersion", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String checkVersion(@RequestBody RequestBase request){
        String retStr = "";
        try {
            retStr = appConfigService.checkVersion(request);
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        return retStr;
    }



    @RequestMapping(value = "/getConfig", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getConfig(@RequestBody RequestBase request){
        String retStr = "";
        try {
            retStr = appConfigService.getConfig(request);
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        return retStr;

    }

    @RequestMapping(value = "/addAdvise", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String addAdvise(@RequestBody AdviseRequest request){
        String retStr = "";
        try {
            retStr = appConfigService.addAdvise(request);
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        return retStr;

    }


    @RequestMapping(value = "/relation", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String addAdvise(@RequestBody ProductRequest request){
        String retStr = "";
        try {
            retStr = appConfigService.relation(request);
        } catch (Exception e) {
            retStr = ResponseOptUtil.commonMsgError( ResponseOptUtil.RET_FAIL_MSG);
            e.printStackTrace();
        }
        return retStr;
    }


}
